package shiyanbaogao;

import java.util.Scanner;

public class PaymentSystem {
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);

            while(true) {
                System.out.println("\n请选择支付方式：");
                System.out.println("1. 银行卡支付");
                System.out.println("2. 支付宝支付");
                System.out.println("3. 微信支付");
                System.out.println("0. 退出系统");
                System.out.print("请输入选项：");

                int choice;
                try {
                    choice = scanner.nextInt();
                } catch (Exception e) {
                    System.out.println("输入格式错误，请重新输入！");
                    scanner.nextLine(); // 清除无效输入
                    continue;
                }

                if(choice == 0) {
                    System.out.println("系统已退出");
                    break;
                }

                Payment payment = null;
                switch(choice) {
                    case 1:
                        payment = new BankCardPayment();
                        break;
                    case 2:
                        payment = new AlipayPayment();
                        break;
                    case 3:
                        payment = new WechatPayment();
                        break;
                    default:
                        System.out.println("无效的选项，请重新输入！");
                        continue;
                }

                System.out.print("请输入支付金额：");
                double amount = scanner.nextDouble();
                // 6. 使用接口多态性
                payment.pay(amount);
            }

            scanner.close();
        }
    }

